//
//  UIView+CYViewExtension.h
//  SafetyInHand
//
//  Created by admin on 2022/7/21.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

#define WITH_ANIMATE                        withAnimate:(BOOL)animate;
#define FINISHED_BLOCK                      (void(^)(BOOL finished))completion
#define WITH_ANIMATE_COMPLETION             withAnimate:(BOOL)animate completion:FINISHED_BLOCK;
#define WITH_ANIMATE_DURATION_COMPLETION    withAnimate:(BOOL)animate animateDuration:(NSTimeInterval)duration completion:FINISHED_BLOCK

@interface UIView (ZZViewExtension)
@property (assign, nonatomic) CGFloat cy_x;
@property (assign, nonatomic) CGFloat cy_y;
@property (assign, nonatomic) CGFloat cy_width;
@property (assign, nonatomic) CGFloat cy_height;
@property (assign, nonatomic) CGFloat cy_centerX;
@property (assign, nonatomic) CGFloat cy_centerY;
@property (assign, nonatomic) CGFloat cy_top;
@property (assign, nonatomic) CGFloat cy_right;
@property (assign, nonatomic) CGFloat cy_bottom;
@property (assign, nonatomic) CGFloat cy_left;
@property (assign, nonatomic) CGSize  cy_size;

+ (UIWindow *)cy_keyWindow;
+ (UIScreen *)cy_mainScreen;
+ (CGRect)cy_mainScreenBounds;

- (void)cy_setX:(CGFloat)x WITH_ANIMATE;
- (void)cy_setY:(CGFloat)y WITH_ANIMATE;
- (void)cy_setWidth:(CGFloat)width WITH_ANIMATE;
- (void)cy_setHeight:(CGFloat)height WITH_ANIMATE;
- (void)cy_setCenterX:(CGFloat)centerX WITH_ANIMATE;
- (void)cy_setCenterY:(CGFloat)centerY WITH_ANIMATE;
- (void)cy_setTop:(CGFloat)top WITH_ANIMATE;
- (void)cy_setRight:(CGFloat)right WITH_ANIMATE;
- (void)cy_setBottom:(CGFloat)bottom WITH_ANIMATE;
- (void)cy_setLeft:(CGFloat)left WITH_ANIMATE;

- (void)cy_setX:(CGFloat)x WITH_ANIMATE_COMPLETION;
- (void)cy_setY:(CGFloat)y WITH_ANIMATE_COMPLETION;
- (void)cy_setWidth:(CGFloat)width WITH_ANIMATE_COMPLETION;
- (void)cy_setHeight:(CGFloat)height WITH_ANIMATE_COMPLETION;
- (void)cy_setCenterX:(CGFloat)centerX WITH_ANIMATE_COMPLETION;
- (void)cy_setCenterY:(CGFloat)centerY WITH_ANIMATE_COMPLETION;
- (void)cy_setTop:(CGFloat)top WITH_ANIMATE_COMPLETION;
- (void)cy_setRight:(CGFloat)right WITH_ANIMATE_COMPLETION;
- (void)cy_setBottom:(CGFloat)bottom WITH_ANIMATE_COMPLETION;
- (void)cy_setLeft:(CGFloat)left WITH_ANIMATE_COMPLETION;

- (void)cy_setX:(CGFloat)x WITH_ANIMATE_DURATION_COMPLETION;
- (void)cy_setY:(CGFloat)y WITH_ANIMATE_DURATION_COMPLETION;
- (void)cy_setWidth:(CGFloat)width WITH_ANIMATE_DURATION_COMPLETION;
- (void)cy_setHeight:(CGFloat)height WITH_ANIMATE_DURATION_COMPLETION;
- (void)cy_setCenterX:(CGFloat)centerX WITH_ANIMATE_DURATION_COMPLETION;
- (void)cy_setCenterY:(CGFloat)centerY WITH_ANIMATE_DURATION_COMPLETION;
- (void)cy_setTop:(CGFloat)top WITH_ANIMATE_DURATION_COMPLETION;
- (void)cy_setRight:(CGFloat)right WITH_ANIMATE_DURATION_COMPLETION;
- (void)cy_setBottom:(CGFloat)bottom WITH_ANIMATE_DURATION_COMPLETION;
- (void)cy_setLeft:(CGFloat)left WITH_ANIMATE_DURATION_COMPLETION;

#pragma mark - NewFrame
- (CGRect)cy_newFrameWithX:(CGFloat)x;
- (CGRect)cy_newFrameWithY:(CGFloat)y;
- (CGRect)cy_newFrameWithWidth:(CGFloat)width;
- (CGRect)cy_newFrameWithHeight:(CGFloat)height;
- (CGRect)cy_newFrameWithRight:(CGFloat)right;
- (CGRect)cy_newFrameWithBottom:(CGFloat)bottom;

#pragma mark - NewCenter
- (CGPoint)cy_newCenterWithCenterX:(CGFloat)centerX;
- (CGPoint)cy_newCenterWithCenterY:(CGFloat)centerY;

/*
 * 裁剪成一个圆
 */
- (void)cy_setLayerCornerRadius;
- (void)cy_setLayerCornerRadiusWithRadius:(CGFloat)radius;
- (void)cy_setBorderWidth:(CGFloat)width borderColor:(CGColorRef)borderColor;
- (void)cy_setBorderWidth:(CGFloat)width borderColor:(CGColorRef)borderColor radius:(CGFloat)radius;
- (void)cy_shadowDefault;
- (void)cy_setLayerShadow:(UIColor *)color shadowOffset:(CGSize)offset shadowOpacity:(CGFloat)opacity shadowRadius:(CGFloat)shadowRadius cornerRadius:(CGFloat)cornerRadius;
- (void)cy_setViewRoundingCorners:(UIRectCorner)corners cornerRadii:(CGSize)cornerRadii;
- (void)cy_setViewRoundingCorners:(UIRectCorner)corners cornerRadius:(CGFloat)radius;

/**
 *  加载xib
 */
+ (id)cy_loadFromNib;
+ (NSString *)cy_ClassStr;

/**
 *  RotateAnimation
 */
- (void)cy_startRotationWithDisableViews:(NSArray *)disableViews;
- (void)cy_rotateAnimation;
- (void)cy_stopRotationDisableViews:(NSArray *)disableViews;

/**
 *  移除所有手势
 */
- (void)cy_removeAllGesture;

#pragma mark - ShowAndHideView
- (void)cy_showInViewWithZoom:(UIView *)aView;
- (void)cy_removeWithZoomFromView:(UIView *)aView completion:(void(^)(BOOL finished))completion;
+ (void)cy_setCoverViewTouchBlock:(void(^)())coverViewTouchBlock;
+ (UIView *)cy_showCoverViewInSuperView:(UIView *)superView withCompletedBlock:(void(^)())completedblock;
+ (UIView *)cy_showCoverViewInSuperView:(UIView *)superView withCoverViewTouchBlock:(void(^)())touchBlock completedBlock:(void(^)())completedblock;
+ (UIView *)cy_showCoverViewInSuperView:(UIView *)superView frame:(CGRect)frame withCoverViewBgColor:(UIColor *)bgColor alpha:(CGFloat)alpha coverViewTouchEnable:(BOOL)enable coverViewTouchBlock:(void(^)())touchBlock completedBlock:(void(^)())completedBlock;
- (void)cy_pushInView:(UIView *)aView completion:(void(^)(BOOL finished))completion;
- (void)cy_popFromView:(UIView *)aView completion:(void(^)(BOOL finished))completion;
- (void)cy_setAlpha:(CGFloat)alpha isAnimation:(BOOL)isAnimation duration:(NSTimeInterval)duration completionBlock:(void(^)())completion;

- (void)cy_showZoomAnimationView;
- (void)cy_dismissViewCompletedBlock:(void(^)())completedBlock;

#pragma mark - 绘制
/**
 ** lineView:       需要绘制成虚线的view
 ** lineLength:     虚线的宽度
 ** lineSpacing:    虚线的间距
 ** lineColor:      虚线的颜色
 **/
+ (CAShapeLayer *)cy_drawDashLine:(UIView *)lineView lineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor *)lineColor;

/**
 ** lineView:       需要绘制成虚线的view
 ** cornerRadius:   虚线拐角的弧度
 ** lineLength:     虚线的宽度
 ** lineSpacing:    虚线的间距
 ** lineColor:      虚线的颜色
 **/
+ (CAShapeLayer *)cy_drawDashedBorderAroundView:(UIView *)lineView cornerRadius:(CGFloat)cornerRadius lineWidth:(CGFloat)lineWidth lineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor*)lineColor;


/**
 获取View的图像(截屏)

 @return View的UIImage对象
 */
- (UIImage *)cy_getViewImage;

#pragma mark - Autoresizing
- (void)cy_setAutoresizeMaskAll;

#pragma mark - Layout
- (void)cy_setLayoutWidthEqualConstraint:(CGFloat)constraint;
- (void)cy_setLayoutHeightEqualConstraint:(CGFloat)constraint;
/**
 * 宽高设置为相等大小
 */
- (void)cy_setLayoutEqualConstraint:(CGFloat)constraint;

@end

@interface UIView (ZZViewController)

/**
 view所在的viewController
 */
- (UIViewController *)cy_getCurrentViewInViewController;
@end

@interface UIView (SSViewSpecialProcess)

/**
 设置通用的紫色背景的渐进色

 @param frame 渐进色的范围
 */
- (void)cy_bgViewSetPurpleColorGradient:(CGRect)frame;
@end
NS_ASSUME_NONNULL_END
